<template>
  <div class="main">

    <!--搜索部分-->
    <div class="user-search-container">



      <el-form ref="params" :inline="true" v-show="true" label-width="68px">

        <el-form-item label="用户编号" prop="username">
          <el-input v-model="params.username" placeholder="请输入用户编号" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="params.type" placeholder="类型" clearable size="small" class="item-input">
            <el-option v-for="dict in ACTION_TYPE" :key="dict.value" :label="dict.text" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="params.city" placeholder="请输入城市" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="queryList(true)">搜索</el-button>
        </el-form-item>
      </el-form>

    </div>

    <!--列表部分-->
    <div class="user-list-container">

      <van-divider />

      <el-table v-loading="loading" :data="list">
        <el-table-column label="id" align="center" prop="id"/>
        <el-table-column label="类型" align="center" prop="type"/>
        <el-table-column label="用户名" align="center" prop="username"/>
        <el-table-column label="地址" align="center" prop="city"/>
        <el-table-column label="喜欢类型" align="center" prop="destType"/>
        <el-table-column label="时间类型" align="center" prop="timeType"/>
        <el-table-column label="相片" align="center" prop="images"/>
        <el-table-column label="微信" align="center" prop="wechat"/>
        <el-table-column label="描述" align="center" prop="instr"/>
        <el-table-column label="喜欢" align="center" prop="joinUids"/>
        <el-table-column label="更新时间" align="center" prop="updateTime"/>
        <el-table-column label="创建时间" align="center" prop="createTime"/>



        <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="params.page" :limit.sync="params.limit" @pagination="onLoad" />
    </div>


  </div>
</template>
<script>
  import { actionPage} from '@/api/friend';
  import commentUtil from "@/utils/commentUtil";
  import {ACTION_TYPE, GENDER} from "../../../comm/constant";

  export default {


    data() {
      return {
        params:{
          username: null,
          ower: null,
          type: null,
          gender: null,
          city: null,
          limit: 10,
          page: 1,
        },
        GENDER_TYPE: GENDER,
        ACTION_TYPE: ACTION_TYPE,
        dateRange: [],
        total:0,
        list: [],
        loading: false,
        isLoading: false,
        showPartnerLv: false,
        selUser: null,
        selectUsers: [],
        userPhone: null,

      }
    },
    methods: {
      moveToParent(){},

      queryList(isSearch){//
        if(this.isLoading) return;
        this.isLoading = true;
        if(isSearch)this.params.page = 1;
        //时间初始化
        if(this.dateRange && this.dateRange.length > 0){
          this.params.startTime = commentUtil.formatStartDate(this.dateRange[0]);
          this.params.endTime = commentUtil.formatEndDate(this.dateRange[1]);
        }else {
          this.params.startTime = null;
          this.params.endTime = null;
        }

        actionPage(this.params).then(res => {
          if(res.data.records){
            console.info("数据条数:" + res.data.records.length);
            res.data.records.forEach(item =>{
              item.trusted = item.isTrusted != null && item.isTrusted === 1;
            });
          }
          this.list = res.data.records;
          this.total = res.data.total;
          this.loading = false;
          this.isLoading = false;
        });
      },
      onClickLeft() {
        this.$router.go(-1);
      },
      onLoad() {
        console.info("加载数据中 第" + this.params.page + "页" )
        this.queryList(false)
      },
      handleDetail(item) {
        this.$router.push({
          path: "/friend/user/detail",
          query: {
            username: item.username,
          }
        });
      },
    },
    mounted() {
      this.onLoad();
    },

  }
</script>
<style scoped>


  .user-search-container, .user-list-container{
    margin: 8px 17px;
  }
  .user-search-container .van-cell{
    margin: 8px 0px;
  }

  .user-search-container .van-dropdown-menu{
    height: 40px;
    margin: 8px 0px;
  }
  .user-search-container .van-button{
    height: 85px;
    width: 100px;
    background-color: #eeeeee;
    margin: 8px 0px;
  }
  .user-search-container .van-field, .user-search-container .van-cell{
    border: 1px solid #eeeeee;
  }
</style>
